define(['jquery', 'bootstrap', 'form'], function ($, undefined, Form) {
    var Controller = {
        index: function () {
            //切换显示隐藏变量字典列表
            $(document).on("change", "form#add-form select[name='row[type]']", function (e) {
                $("#add-content-container").toggleClass("hide", ['select', 'selects', 'checkbox', 'radio'].indexOf($(this).val()) > -1 ? false : true);
            });
            //选择规则
            $(document).on("click", ".dropdown-menu > li > a", function () {
                var value = $("#rule").val();
                var ruleArr = value == '' ? [] : value.split(";");
                var rule = $(this).data("value");
                var index = ruleArr.indexOf(rule);
                if (index > -1) {
                    ruleArr.splice(index, 1);
                } else {
                    ruleArr.push(rule);
                }
                $("#rule").val(ruleArr.join(";"));
                $(this).parent().toggleClass("active");
            });
            Controller.api.bindevent();

        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        events: {},
        api: {
            bindevent: function () {
                var form = $('form[role="form"]');
                Form.api.bindevent(form);
            }
        }

    };
    return Controller;
});
